﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AspNetCore31.DemoProject.Controllers
{
    public class FirstController : Controller
    {
        #region Identity
        private IConfiguration _iConfiguration;
        #endregion
         
        public FirstController(IConfiguration configuration)
        {
            this._iConfiguration = configuration;
        }

        /// <summary>
        /// 统计请求次数
        /// </summary>
        public static int _TotbalCount = 0;

        public IActionResult Index()
        {
            #region 地址信息
            this.ViewBag.BrowserUrl = $"{base.Request.Scheme}://{base.Request.Host}:{base.Request.Host.Port}";
            this.ViewBag.InternalUrl = $"{base.Request.Scheme}://{base.Request.Host.Host}:{this._iConfiguration["port"]}";
            this.ViewBag.TotalCount = _TotbalCount++;
            #endregion

            #region Session
            string user = base.HttpContext.Session.GetString("CurrentUser");
            if (string.IsNullOrWhiteSpace(user))
            {
                base.HttpContext.Session.SetString("CurrentUser", $"XLB-{this._iConfiguration["port"]}");
            }
            base.ViewBag.SessionUser=base.HttpContext.Session.GetString("CurrentUser");
            #endregion
            return View();
        }
    }
}
